package cn.doitedu.benchmark;

import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.ArrayList;

/***
 * @author hunter.d
 * @qq 657270652
 * @wx haitao-duan
 * @date 2021/3/25
 **/
public class GenProfileData {
    public static void main(String[] args) throws Exception {

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","hdp01:2181,hdp02:2181,hdp03:2181");
        Connection conn = ConnectionFactory.createConnection(conf);
        Table profileTable = conn.getTable(TableName.valueOf("user_profile"));

        ArrayList<Put> puts = new ArrayList<>();
        while (true) {

            for(int i=0;i<20;i++) {
                String account = StringUtils.leftPad(RandomStringUtils.randomNumeric(4), 4, "0");
                Put put = new Put(Bytes.toBytes(account));
                put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("vip"), Bytes.toBytes("vip-" + RandomUtils.nextInt(1, 4)));
                put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("sex"), Bytes.toBytes(RandomUtils.nextInt(0, 2) + ""));
                put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("age"), Bytes.toBytes(RandomUtils.nextInt(18, 60) + ""));
                put.addColumn(Bytes.toBytes("f"), Bytes.toBytes("cst"), Bytes.toBytes(RandomUtils.nextInt(0, 6000) + ""));
                puts.add(put);
            }
            profileTable.put(puts);
            puts.clear();

            Thread.sleep(10);
        }
    }
}
